using CoreManager.MessageQueue.Models;

namespace CoreManager.MessageQueue.Services;

/// <summary>
/// Kafka消费者服务接口
/// </summary>
public interface IKafkaConsumerService
{
    /// <summary>
    /// 订阅主题
    /// </summary>
    /// <param name="topics">主题列表</param>
    void Subscribe(params string[] topics);
    
    /// <summary>
    /// 订阅主题
    /// </summary>
    /// <param name="topics">主题列表</param>
    void Subscribe(IEnumerable<string> topics);
    
    /// <summary>
    /// 开始消费消息
    /// </summary>
    /// <param name="messageHandler">消息处理器</param>
    /// <param name="cancellationToken">取消令牌</param>
    /// <returns></returns>
    Task StartConsumingAsync(Func<string, KafkaMessage, Task<bool>> messageHandler, CancellationToken cancellationToken = default);
    
    /// <summary>
    /// 开始消费消息（泛型）
    /// </summary>
    /// <typeparam name="T">消息数据类型</typeparam>
    /// <param name="messageHandler">消息处理器</param>
    /// <param name="cancellationToken">取消令牌</param>
    /// <returns></returns>
    Task StartConsumingAsync<T>(Func<string, KafkaMessage<T>, Task<bool>> messageHandler, CancellationToken cancellationToken = default);
    
    /// <summary>
    /// 停止消费
    /// </summary>
    void StopConsuming();
    
    /// <summary>
    /// 手动提交偏移量
    /// </summary>
    void CommitOffset();
    
    /// <summary>
    /// 释放资源
    /// </summary>
    void Dispose();
}
